package com.zk.iotgateway.domain.locator;

import com.zk.iotgateway.util.StringUtils;
import lombok.Data;

import java.io.Serializable;

/**
 * 定位器do
 *
 * @author:mn.m
 * @create 2019-06-03 上午 10:02
 **/
@Data
public class LocatorDO implements Serializable {
    private static final long serialVersionUID = -3543586825999837860L;

    public LocatorDO(String msg){
        int len =msg.length();
        String type =msg.substring(6,8);
        this.setMsgType(type);
        if (type!=null){
            //gps定位数据包
           if("10".equals(type)){
                setContent(msg.substring(8,len-4));
           //状态包 13
            }else if("13".equals(type)){
               //电量
//               int s =StringUtils.hexStringToAlgorism(msg.substring(8,10));
//               setContent(String.valueOf(s));
               setContent(msg.substring(8,len-4));
            //登录包 01
            }else if("01".equals(type)){
               this.setContent(msg.substring(8,len-6));
            }
            //心跳包08
            this.setHeader(msg.substring(0,4));
            this.setLenArea(msg.substring(4,6));
            this.setEnd(msg.substring(len-4));
        }

    }

    //报文头 "7878"
    private String header;
    //报文长度
    private String  lenArea;
    //协议类型  0x08 表示心跳包    0x01 表示登录包
    private String msgType;
    //报文体
    private String content;
    //结尾 "0D0A"
    private String end ;


    @Override
    public String toString() {

        return null;
    }
}
